import { ref } from 'vue'
import type { NavLink } from '../types'

// 创建单例状态
const currentPage = ref<string>('首页')
const navLinks = ref<NavLink[]>([
  { name: '首页', active: true },
  { name: '检验记录', active: false },
  { name: '规则管理', active: false },
  { name: '设置', active: false }
])

export function useHeaderNavStore() {
  const setActiveLink = (linkName: string) => {
    navLinks.value.forEach(link => {
      link.active = link.name === linkName
    })
    currentPage.value = linkName
  }

  const updateActiveLink = (linkName: string) => {
    setActiveLink(linkName)
  }

  return {
    currentPage,
    navLinks,
    setActiveLink,
    updateActiveLink
  }
}